//输入框1
var inputO = document.querySelector(".formula .mula .inputO");
//计算符号
var symbol = document.querySelector(".formula .mula select");
//输入框2
var inputT = document.querySelector(".formula .mula .inputT");
//输出框
var result = document.querySelector(".formula .result");
//展示按钮事件
var btn = document.querySelector(".formula .btn");
//大数字框(十位)
var dnumd = document.querySelector(".process .con .addsub .f1 .f1-decade .f1-decade-num");
//大数字框(个位)
var dnumu = document.querySelector(".process .con .addsub .f1 .f1-units");
//借位符(十位)
var bor = document.querySelector(".process .con .addsub .f1 .f1-decade .f1-bor");
//符号框
var symbolbox = document.querySelector(".process .con .addsub .f2 .f2-symbol");
//小数字框(十位)
var xnumd = document.querySelector(".process .con .addsub .f2 .f2-decade .f2-decade-num");
//小数字框(个位)
var xnumu = document.querySelector(".process .con .addsub .f2 .f2-units");
//上部分进位(百位)
var carryhT = document.querySelector(".process .con .addsub .f2 .f2-hundreds .f2-carryh");
//上部分进位(十位)
var carrydT = document.querySelector(".process .con .addsub .f2 .f2-decade .f2-carryd");
//横线(上)
var line = document.querySelector(".process .f3");
//上部分结果(百位)
var resultshT = document.querySelector(".process .con .addsub .f3 .f3-hundreds");
//上部分结果(十位)
var resultsdT = document.querySelector(".process .con .addsub .f3 .f3-decade");
//上部分结果(个位)
var resultsuT = document.querySelector(".process .con .addsub .f3 .f3-units");
//下部分结果(千位)
var resultskB = document.querySelector(".process .con .addsub .f4 .f4-kilobit .f4-kilobit-num");
//下部分结果(百位)
var resultshB = document.querySelector(".process .con .addsub .f4 .f4-hundreds .f4-hundreds-num");
//下部分结果(十位)
var resultsdB = document.querySelector(".process .con .addsub .f4 .f4-decade");
//中间部分进位(百位)
var carryhZ = document.querySelector(".process .con .addsub .f4 .f4-hundreds .f4-carryh-z");
//下部分进位(千位)
var carrykB = document.querySelector(".process .con .addsub .f4 .f4-kilobit .f4-carryk");
//下部分进位(百位)
var carryhB = document.querySelector(".process .con .addsub .f4 .f4-hundreds .f4-carryh");
//横线(下)
var lines = document.querySelector(".process .con .addsub .f5");
//乘法
//总结果(千位)
var resultskZ = document.querySelector(".process .con .addsub .f5 .f5-kilobit");
//总结果(百位)
var resultshZ = document.querySelector(".process .con .addsub .f5 .f5-hundreds");
//总结果(十位)
var resultsdZ = document.querySelector(".process .con .addsub .f5 .f5-decade");
//总结果(个位)
var resultsuZ = document.querySelector(".process .con .addsub .f5 .f5-units");
//计算结果函数
function cal() {
  let v1 = inputO.value;
  let v2 = symbol.options[symbol.options.selectedIndex].innerText;
  let v3 = inputT.value;
  if (inputO.value && inputT.value) {
    if (v2 == "/" && v1 == 0 && v3 == 0) {
      result.style.fontSize = "16px";
      result.value = "无法计算";
    } else if (v2 == "/" && v1 != 0 && v3 == 0) {
      result.style.fontSize = "16px";
      result.value = "无法计算";
    } else {
      result.style.fontSize = "24px";
      let str = v1 + v2 + v3;
      result.value = eval(str);
    }
  } else {
    result.value = "?";
  }
}
//展示按钮悬浮事件
btn.onmouseover = function () {
  let v1 = inputO.value;
  let v2 = symbol.options[symbol.options.selectedIndex].innerText;
  let v3 = inputT.value;
  line.style.borderTop = "1px solid black";
  // 符号
  symbolbox.innerText = v2;
  if (v1 == "" && v3 == "") {
    return;
  }
  if (v2 == "+") {
    // 比数字大小
    if (v1 * 1 >= v3 * 1) {
      // 数字位数
      if ([...v1].length == 1) {
        dnumu.innerText = [...v1][0];
        // 是否进位
        if (eval([...v1][0] + v2 + [...v3][0]) >= 10) {
          carrydT.innerText = "1";
        }
      } else if ([...v1].length == 2) {
        dnumd.innerText = [...v1][0];
        dnumu.innerText = [...v1][1];
        // 是否进位
        if (eval([...v1][1] + v2 + [...v3][[...v3].length - 1]) >= 10) {
          carrydT.innerText = "1";
        }
      }
      // 数字位数
      if ([...v3].length == 1) {
        xnumu.innerText = [...v3][0];
      } else if ([...v3].length == 2) {
        xnumd.innerText = [...v3][0];
        xnumu.innerText = [...v3][1];
        // 是否进位
        if (eval([...v1][0] + v2 + [...v3][0]) >= 10) {
          carryhT.innerText = "1";
        }
      }
      let str = eval(v1 + v2 + v3).toString();
      // 结果位数
      if ([...str].length == 1) {
        resultsuT.innerText = [...str][0];
      } else if ([...str].length == 2) {
        resultsdT.innerText = [...str][0];
        resultsuT.innerText = [...str][1];
      } else if ([...str].length == 3) {
        resultshT.innerText = [...str][0];
        resultsdT.innerText = [...str][1];
        resultsuT.innerText = [...str][2];
      }
    } else {
      // 数字位数
      if ([...v1].length == 1) {
        xnumu.innerText = [...v1][0];
      } else if ([...v1].length == 2) {
        xnumd.innerText = [...v1][0];
        xnumu.innerText = [...v1][1];
        // 是否进位
        if (eval([...v1][0] + v2 + [...v3][0]) >= 10) {
          carryhT.innerText = "1";
        }
      }
      // 数字位数
      if ([...v3].length == 1) {
        dnumu.innerText = [...v3][0];
        // 是否进位
        if (eval([...v1][0] + v2 + [...v3][0]) >= 10) {
          carrydT.innerText = "1";
        }
      } else if ([...v3].length == 2) {
        dnumd.innerText = [...v3][0];
        dnumu.innerText = [...v3][1];
        // 是否进位
        if (eval([...v1][[...v1].length - 1] + v2 + [...v3][1]) >= 10) {
          carrydT.innerText = "1";
        }
      }
      let str = eval(v1 + v2 + v3).toString();
      // 结果位数
      if ([...str].length == 1) {
        resultsuT.innerText = [...str][0];
      } else if ([...str].length == 2) {
        resultsdT.innerText = [...str][0];
        resultsuT.innerText = [...str][1];
      } else if ([...str].length == 3) {
        resultshT.innerText = [...str][0];
        resultsdT.innerText = [...str][1];
        resultsuT.innerText = [...str][2];
      }
    }
  } else if (v2 == "-") {
    // 数字位数
    if ([...v1].length == 1) {
      dnumu.innerText = [...v1][0];
    } else if ([...v1].length == 2) {
      dnumd.innerText = [...v1][0];
      dnumu.innerText = [...v1][1];
    }
    if ([...v3].length == 1) {
      xnumu.innerText = [...v3][0];
    } else if ([...v3].length == 2) {
      xnumd.innerText = [...v3][0];
      xnumu.innerText = [...v3][1];
    }
    let str = eval(v1 + v2 + v3).toString();
    if ([...str].length == 1) {
      resultsuT.innerText = [...str][0];
    } else if ([...str].length == 2) {
      resultsdT.innerText = [...str][0];
      resultsuT.innerText = [...str][1];
    } else if ([...str].length == 3) {
      resultshT.innerText = [...str][0];
      resultsdT.innerText = [...str][1];
      resultsuT.innerText = [...str][2];
    }
    //是否借位
    if (eval([...v1][[...v1].length - 1] + v2 + [...v3][[...v3].length - 1]) < 0) {
      bor.innerText = ".";
    }
  } else if (v2 == "*") {
    if (v1 * 1 >= v3 * 1) {
      // 数字位数
      if ([...v1].length == 1) {
        dnumu.innerText = [...v1][0];
        xnumu.innerText = [...v3][0];
        // 是否进位
        if (eval([...v1][0] + v2 + [...v3][0]) >= 10) {
          carrydT.innerText = [...eval([...v1][0] + v2 + [...v3][0]).toString()][0];
          resultsdT.innerText = [...eval([...v1][0] + v2 + [...v3][0]).toString()][0];
          resultsuT.innerText = [...eval([...v1][0] + v2 + [...v3][0]).toString()][1];
        } else {
          resultsuT.innerText = [...eval([...v1][0] + v2 + [...v3][0]).toString()][0];
        }
      }
      // 数字位数
      if ([...v1].length == 2 && [...v3].length == 1) {
        dnumd.innerText = [...v1][0];
        dnumu.innerText = [...v1][1];
        xnumu.innerText = [...v3][0];
        // 是否进位
        if (eval([...v1][1] + v2 + v3) >= 10) {
          carrydT.innerText = [...eval([...v1][1] + v2 + v3).toString()][0];
        }
        if (eval([...v1][0] + v2 + v3) >= 10) {
          carryhT.innerText = [...eval([...v1][0] + v2 + v3).toString()][0];
        }
        if (eval(v1 + v2 + v3) >= 100) {
          resultshT.innerText = [...eval(v1 + v2 + v3).toString()][0];
          resultsdT.innerText = [...eval(v1 + v2 + v3).toString()][1];
          resultsuT.innerText = [...eval(v1 + v2 + v3).toString()][2];
          if ([...eval(v1 + v2 + v3).toString()][1] == 0 && [...eval(v1 + v2 + v3).toString()][0] == 1) {
            carryhT.innerText = "1";
          }
        } else {
          resultsdT.innerText = [...eval(v1 + v2 + v3).toString()][0];
          resultsuT.innerText = [...eval(v1 + v2 + v3).toString()][1];
        }
      }
      if ([...v3].length == 2) {
        // 数字位数
        dnumd.innerText = [...v1][0];
        dnumu.innerText = [...v1][1];
        xnumd.innerText = [...v3][0];
        xnumu.innerText = [...v3][1];
        lines.style.borderTop = "1px solid black";
        if (eval(v1 + v2 + [...v3][1]) >= 100) {
          resultshT.innerText = [...eval(v1 + v2 + [...v3][1]).toString()][0];
          resultsdT.innerText = [...eval(v1 + v2 + [...v3][1]).toString()][1];
          resultsuT.innerText = [...eval(v1 + v2 + [...v3][1]).toString()][2];
        } else {
          resultsdT.innerText = [...eval(v1 + v2 + [...v3][1]).toString()][0];
          resultsuT.innerText = [...eval(v1 + v2 + [...v3][1]).toString()][1];
        }
        if (eval([...v1][1] + v2 + [...v3][0]) >= 10) {
          carryhZ.innerText = [...eval([...v1][1] + v2 + [...v3][0]).toString()][0];
          resultsdB.innerText = [...eval([...v1][1] + v2 + [...v3][0]).toString()][1];
        } else {
          resultsdB.innerText = eval([...v1][1] + v2 + [...v3][0]);
        }
        if (eval([...v1][0] + v2 + [...v3][0]) >= 10) {
          resultskB.innerText = [...eval([...v1][0] + v2 + [...v3][0]).toString()][0];
          resultshB.innerText = [...eval([...v1][0] + v2 + [...v3][0]).toString()][1];
        } else {
          resultshB.innerText = eval([...v1][0] + v2 + [...v3][0]);
        }
        if (eval(v1 + v2 + v3) >= 1000) {
          resultskZ.innerText = [...eval(v1 + v2 + v3).toString()][0];
          resultshZ.innerText = [...eval(v1 + v2 + v3).toString()][1];
          resultsdZ.innerText = [...eval(v1 + v2 + v3).toString()][2];
          resultsuZ.innerText = [...eval(v1 + v2 + v3).toString()][3];
        } else {
          resultshZ.innerText = [...eval(v1 + v2 + v3).toString()][0];
          resultsdZ.innerText = [...eval(v1 + v2 + v3).toString()][1];
          resultsuZ.innerText = [...eval(v1 + v2 + v3).toString()][2];
        }
        // 是否进位
        if (eval([...v1][1] + v2 + [...v3][1]) >= 10) {
          carrydT.innerText = [...eval([...v1][1] + v2 + [...v3][1]).toString()][0];
        }
        if (eval([...v1][0] + v2 + [...v3][1] + "+" + carrydT.innerText) >= 10) {
          carryhT.innerText = [...eval([...v1][0] + v2 + [...v3][1] + "+" + carrydT.innerText).toString()][0];
        }
        if (eval(v1 + v2 + [...v3][1]) >= 100 && [...eval(v1 + v2 + [...v3][0]).toString()][1] == 0 && [...eval(v1 + v2 + [...v3][0]).toString()][0] == 1) {
          carryhT.innerText = "1";
        }
        if (eval(resultsdT.innerText + "+" + resultsdB.innerText) >= 10) {
          carryhB.innerText = "1";
        }
        if (eval(resultshT.innerText + "+" + resultshB.innerText) >= 10 && eval(resultshT.innerText + "+" + resultshB.innerText) < 20) {
          carrykB.innerText = "1";
        }
        if (eval(resultshT.innerText + "+" + resultshB.innerText + "+" + carryhZ.innerText + "+" + carryhB.innerText) >= 20) {
          carrykB.innerText = "2";
        }
      }
    } else {
      // 数字位数
      if ([...v1].length == 2) {
        // 数字位数
        dnumd.innerText = [...v3][0];
        dnumu.innerText = [...v3][1];
        xnumd.innerText = [...v1][0];
        xnumu.innerText = [...v1][1];
        lines.style.borderTop = "1px solid black";
        if (eval(v3 + v2 + [...v1][1]) >= 100) {
          resultshT.innerText = [...eval([...v1][1] + v2 + v3).toString()][0];
          resultsdT.innerText = [...eval([...v1][1] + v2 + v3).toString()][1];
          resultsuT.innerText = [...eval([...v1][1] + v2 + v3).toString()][2];
        } else {
          resultsdT.innerText = [...eval([...v1][1] + v2 + v3).toString()][0];
          resultsuT.innerText = [...eval([...v1][1] + v2 + v3).toString()][1];
        }
        if (eval([...v1][0] + v2 + [...v3][1]) >= 10) {
          carryhZ.innerText = [...eval([...v1][0] + v2 + [...v3][1]).toString()][0];
          resultsdB.innerText = [...eval([...v1][0] + v2 + [...v3][1]).toString()][1];
        } else {
          resultsdB.innerText = eval([...v1][0] + v2 + [...v3][1]).toString();
        }
        if (eval([...v1][0] + v2 + [...v3][0]) >= 10) {
          resultskB.innerText = [...eval([...v1][0] + v2 + [...v3][0]).toString()][0];
          resultshB.innerText = [...eval([...v1][0] + v2 + [...v3][0]).toString()][1];
        } else {
          resultshB.innerText = eval([...v1][0] + v2 + [...v3][1]).toString();
        }
        if (eval(v1 + v2 + v3) >= 1000) {
          resultskZ.innerText = [...eval(v1 + v2 + v3).toString()][0];
          resultshZ.innerText = [...eval(v1 + v2 + v3).toString()][1];
          resultsdZ.innerText = [...eval(v1 + v2 + v3).toString()][2];
          resultsuZ.innerText = [...eval(v1 + v2 + v3).toString()][3];
        } else {
          resultshZ.innerText = [...eval(v1 + v2 + v3).toString()][0];
          resultsdZ.innerText = [...eval(v1 + v2 + v3).toString()][1];
          resultsuZ.innerText = [...eval(v1 + v2 + v3).toString()][2];
        }
        // 是否进位
        if (eval([...v1][1] + v2 + [...v3][1]) >= 10) {
          carrydT.innerText = [...eval([...v1][1] + v2 + [...v3][1]).toString()][0];
        }
        if (eval([...v1][1] + v2 + [...v3][0] + "+" + carrydT.innerText) >= 10) {
          carryhT.innerText = [...eval([...v1][1] + v2 + [...v3][0] + "+" + carrydT.innerText).toString()][0];
        }
        if (eval([...v1][1] + v2 + v3) >= 100 && [...eval([...v1][1] + v2 + v3).toString()][1] == 0 && [...eval([...v1][1] + v2 + v3).toString()][0] == 1) {
          carryhT.innerText = "1";
        }
        if (eval(resultsdT.innerText + "+" + resultsdB.innerText) >= 10) {
          carryhB.innerText = "1";
        }
        if (eval(resultshT.innerText + "+" + resultshB.innerText) >= 10 && eval(resultshT.innerText + "+" + resultshB.innerText) < 20) {
          carrykB.innerText = "1";
        }
        if (eval(resultshT.innerText + "+" + resultshB.innerText + "+" + carryhZ.innerText + "+" + carryhB.innerText) >= 20) {
          carrykB.innerText = "2";
        }
      }
      // 数字位数
      if ([...v3].length == 2 && [...v1].length == 1) {
        dnumd.innerText = [...v3][0];
        dnumu.innerText = [...v3][1];
        xnumu.innerText = [...v1][0];
        // 是否进位
        if (eval(v1 + v2 + [...v3][1]) >= 10) {
          carrydT.innerText = [...eval(v1 + v2 + [...v3][1]).toString()][0];
        }
        if (eval(v1 + v2 + [...v3][0]) >= 10) {
          carryhT.innerText = [...eval(v1 + v2 + [...v3][0]).toString()][0];
        }
        if (eval(v1 + v2 + v3) >= 100) {
          resultshT.innerText = [...eval(v1 + v2 + v3).toString()][0];
          resultsdT.innerText = [...eval(v1 + v2 + v3).toString()][1];
          resultsuT.innerText = [...eval(v1 + v2 + v3).toString()][2];
          if ([...eval(v1 + v2 + v3).toString()][1] == 0 && [...eval(v1 + v2 + v3).toString()][0] == 1) {
            carryhT.innerText = "1";
          }
        } else {
          resultsdT.innerText = [...eval(v1 + v2 + v3).toString()][0];
          resultsuT.innerText = [...eval(v1 + v2 + v3).toString()][1];
        }
      }
      if ([...v3].length == 1) {
        dnumu.innerText = v3;
        xnumu.innerText = v1;
        // 是否进位
        if (eval(v1 + v2 + v3) >= 10) {
          carrydT.innerText = [...eval(v1 + v2 + v3).toString()][0];
          resultsdT.innerText = [...eval(v1 + v2 + v3).toString()][0];
          resultsuT.innerText = [...eval(v1 + v2 + v3).toString()][1];
        } else {
          resultsuT.innerText = [...eval(v1 + v2 + v1).toString()][0];
        }
      }
    }
  } else if (v2 == "/") {
  }
};
//展示按钮移出事件
btn.onmouseout = function () {
  dnumd.innerHTML = "";
  dnumu.innerHTML = "";
  bor.innerHTML = "";
  symbolbox.innerHTML = "";
  xnumd.innerHTML = "";
  xnumu.innerHTML = "";
  carryhT.innerHTML = "";
  carrydT.innerHTML = "";
  line.style.borderTop = "none";
  resultshT.innerHTML = "";
  resultsdT.innerHTML = "";
  resultsuT.innerHTML = "";
  resultskB.innerHTML = "";
  resultshB.innerHTML = "";
  resultsdB.innerHTML = "";
  carryhZ.innerHTML = "";
  carrykB.innerHTML = "";
  carryhB.innerHTML = "";
  lines.style.borderTop = "none";
  resultskZ.innerHTML = "";
  resultshZ.innerHTML = "";
  resultsdZ.innerHTML = "";
  resultsuZ.innerHTML = "";
};
